package com.example.mygame.snake.role;





import com.example.mygame.snake.common.GameConst;

import java.util.Random;

/**
 * Created by Mrper on 15-11-24.
 */
public class Food {

    public interface OnCreateFoodListener{
        void onFinishCreateFood(MapBlock food);
    }

    private Random random = new Random();
    public MapBlock point;
    private OnCreateFoodListener listener;

    public Food(){

    }

    public void setOnCreateFoodListener(OnCreateFoodListener listener){
        this.listener = listener;
    }

    public void createFood(Snake snake){
        point = null;//置空食物点坐标
        int x = random.nextInt(GameConst.MAX_X-1);
        int y = random.nextInt(GameConst.MAX_Y-1);
        for(MapBlock item : snake.body){
            if(item.x == x && item.y == y){
                createFood(snake);
                return;
            }
        }
        point = new MapBlock(x,y);
        if(listener!=null)
            listener.onFinishCreateFood(point);
    }

}
